package com.hspedu.file;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/22
 * @time 17:08
 */
public class FileCreate {
    public static void main(String[] args) {

    }

    @Test
    public void create01(){
        String filePath = "D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\news1.txt";
        File file = new File(filePath);

        try {
            file.createNewFile();
            System.out.println("news1创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void create02(){
        File parentFile = new File("D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\");
        String childFile = "news2.txt";

        File file = new File(parentFile, childFile);

        try {
            file.createNewFile();
            System.out.println("news2创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void create03(){
        String parentPath = "D:\\BaiduNetdiskDownload\\韩顺平2021基础学Java\\temp\\";
        String chileName = "news3.txt";

        File file = new File(parentPath, chileName);

        try {
            file.createNewFile();
            System.out.println("news3创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
